package com.cs.service;

import com.cs.mapper.RoleMapper;
import com.cs.pojo.*;
import com.cs.resultVO.ResultVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class RoleService {
    @Resource
    private RoleMapper roleMapper;
    public List<Role> queryAll(){
        List<Role> roles = roleMapper.selectByExample(null);
        return roles;
    }
    public PageInfo<Role> queryAll2(String rolename, int pageNum, int pageSize){
        RoleExample example=new RoleExample();
        RoleExample.Criteria criteria = example.createCriteria();
        if (rolename!=null){
            if (!rolename.trim().equals("")){
                criteria.andRNameLike("%"+rolename.trim()+"%");
            }
        }
        PageHelper.startPage(pageNum,pageSize);
        List<Role> roles = roleMapper.selectByExample(example);
        return new PageInfo<>(roles);
    }

    public Role queryById(int rId){
        Role role = roleMapper.selectByPrimaryKey(rId);
        return role;
    }

    public int update(Role role){
        int i = roleMapper.updateByPrimaryKeySelective(role);
        return i;
    }

    public int deleteOne(int rId){
        Role role=new Role();
        role.setrId(rId);
        role.setrState(2);
        int i = roleMapper.updateByPrimaryKeySelective(role);
        return i;
    }

    public int add(Role role){
        int insert = roleMapper.insert(role);
        return insert;
    }

    public int deleteList(int rId){
        int i = roleMapper.deleteList(rId);
        return i;
    }

    public int insertMids(Integer rId,Integer mId){
        int i = roleMapper.insertMids(rId, mId);
        return i;
    }
}
